Hello, |
Re: Find and Replace First of all, when posting DXL code, please put "{ c o d e }" before and after the actual code (remove the spaces). This will format the code nicely, and, more important in your specific case, will preserve the angular brackets, which have been removed and replaced by hyperlinks. I can therefore only guess what your original code in line 10 was, I guess something like char check = data[cnt][cnt1:cnt1] .The specific error in this line is that 'char' assignment is done by individual integers, not ranges, hence data[cnt][cnt1]
works.
void RemoveSpaces(string indata[])
{
Buffer buf = create
int cnt = 0, cnt1 = 0
int arrayLen = sizeof indata
char check
for(cnt=0; cnt<arrayLen; cnt++)
{
buf = "" // Empty the buffer for each array element
for(cnt1=0; cnt1<length(indata[cnt]); cnt1++)
{
check = indata[cnt][cnt1]
if ((check != charOf(32)) && (check != charOf(10)) &&
(check != charOf(13)) && (check != charOf(9)))
{
buf+= check
}
}
indata[cnt] = stringOf(buf)
}
delete buf // Don't forget to delete the Buffer
}
string sTmp[] = {"Apple", "Banana", "Man go"}
int i
for i in 0:sizeof sTmp -1 do {print sTmp[i] ","}
print "\n"
RemoveSpaces(sTmp)
for i in 0:sizeof sTmp -1 do {print sTmp[i] ","}
|
Re: Find and Replace Using objective investigation and subjective judgement, I've come up with the following variable that defines each "White Space" character. My "Trim" etc functions use this definition:
If you use that, perhaps you need an inner loop:
bool HasWhite = false
for (j = 0; j < length(cl_White); j++)
{ if (check == cl_White[j]) then HasWhite = true
}
if (!HasWhite) then buf += check
|
Re: Find and Replace llandale - Tue Jun 26 16:30:23 EDT 2012 Using objective investigation and subjective judgement, I've come up with the following variable that defines each "White Space" character. My "Trim" etc functions use this definition:
If you use that, perhaps you need an inner loop:
bool HasWhite = false
for (j = 0; j < length(cl_White); j++)
{ if (check == cl_White[j]) then HasWhite = true
}
if (!HasWhite) then buf += check
Just one nit-pick regarding those loops. One should not use 'length' in the loop condition. The loop condition will be executed in every iteration of the loop. Note that this only applies to strings, not to buffers (which keep their length stored, as long as you do not modify them). This can lead to hard to find performance killers in DXL, because a loop that is supposed to be checking for whitespaces suddenly takes 1000% more time than before (when only small strings were used).
pragma runLim, 0
int i = 0
Buffer bufLong = create();
// create a long string
for (i = 0; i < 20000; i++) { bufLong += 'x' }
// Buffer buf = bufLong // comment me in to test with buffers
string buf = stringOf bufLong
{
int iStart = getTickCount_()
// use length in loop condition
for (i = 0; i < length buf; i++) { }
print "Time with length in loop:" (getTickCount_() - iStart) "\n"
}
{
int iStart = getTickCount_()
// use length in loop condition
int iLen = length buf;
for (i = 0; i < iLen; i++) { }
print "Time with length outside loop:" (getTickCount_() - iStart) "\n"
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Find and Replace Mathias Mamsch - Wed Jun 27 05:14:35 EDT 2012
Just one nit-pick regarding those loops. One should not use 'length' in the loop condition. The loop condition will be executed in every iteration of the loop. Note that this only applies to strings, not to buffers (which keep their length stored, as long as you do not modify them). This can lead to hard to find performance killers in DXL, because a loop that is supposed to be checking for whitespaces suddenly takes 1000% more time than before (when only small strings were used).
pragma runLim, 0
int i = 0
Buffer bufLong = create();
// create a long string
for (i = 0; i < 20000; i++) { bufLong += 'x' }
// Buffer buf = bufLong // comment me in to test with buffers
string buf = stringOf bufLong
{
int iStart = getTickCount_()
// use length in loop condition
for (i = 0; i < length buf; i++) { }
print "Time with length in loop:" (getTickCount_() - iStart) "\n"
}
{
int iStart = getTickCount_()
// use length in loop condition
int iLen = length buf;
for (i = 0; i < iLen; i++) { }
print "Time with length outside loop:" (getTickCount_() - iStart) "\n"
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|